package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.OrderPageInfo;
import com.cskaoyan.bean.goods.bo.CommentBo;
import com.cskaoyan.service.CommentService;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:AdminOrderController
 * @Description:TODO
 * @author:leiwenjie
 * @date:2022/9/7 14:45
 * @version:1.0
 */
@RestController
@RequestMapping("admin/order")
public class AdminOrderController {

    @Autowired
    OrderService orderService;


    @RequestMapping("list")
    public BaseRespVo list(OrderPageInfo info) {
        CommonData<MarketOrder> data = orderService.query(info);

        return BaseRespVo.ok(data);
    }


    @RequestMapping("detail")
    public BaseRespVo detail(int id) {
        MarketOrderGoodsData data = orderService.detail(id);
        return BaseRespVo.ok(data);
    }


    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map<String, Object> map) {


        Integer orderId = (Integer) map.get("orderId");
        BigDecimal refundMoney = BigDecimal.valueOf((int) map.get("refundMoney"));


        orderService.refund(orderId, refundMoney);
        return BaseRespVo.ok(null);
    }


    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody Map<String,Object> map) {
        Integer orderId = (Integer) map.get("orderId");
        String shipChannel = (String) map.get("shipChannel");
        String shipSn = (String) map.get("shipSn");
        MarketOrder marketOrder = new MarketOrder();
        marketOrder.setId(orderId);
        marketOrder.setShipChannel(shipChannel);
        marketOrder.setShipSn(shipSn);
        orderService.ship(marketOrder);
        return BaseRespVo.ok(null);
    }

    @RequestMapping("channel")
    public BaseRespVo channel() {
        List<MarketChannel> list = MarketChannelData.getList();
//orderService.channel();
        return BaseRespVo.ok(list);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map<String, Integer> map) {
        Integer orderId = map.get("orderId");
        orderService.delete(orderId);
        return BaseRespVo.ok(null);

    }




    @RequestMapping("reply")
    public BaseRespVo reply(CommentBo commentBo) {
        orderService.commentReply(commentBo);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }


}
